package short_semester.questionnaire_planet.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.List;

@Data
@Entity
@Table(indexes = {@Index(columnList = "questionId"),@Index(columnList = "type"),
        @Index(columnList = "relationId"),@Index(columnList = "relationType"),})
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
@NoArgsConstructor
@AllArgsConstructor
public class Relation {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))
    private Questionnaire questionnaire;
    
    //题目id
    private Integer questionId;
    //题目类型（radio,checkbox）
    private String type;
    
    //绑定的题目id
    private Integer relationId;
    //（radio,checkbox）
    private String relationType;
    //绑定的选项id
    
    private Integer optionId;
    
    private Boolean isChoose = true;
    private Boolean isAll = false;

    public Relation(Questionnaire questionnaire, Integer questionId, String type, Integer relationId, String relationType, Integer optionId) {
        this.questionnaire = questionnaire;
        this.questionId = questionId;
        this.type = type;
        this.relationId = relationId;
        this.relationType = relationType;
        this.optionId = optionId;
    }
    public void setIs(Boolean isChoose,Boolean isAll){
        this.isChoose = isChoose;
        this.isAll = isAll;
    }
}
